<template>
  <div style="color: red">变量函数提升</div>
  <br />
  <div>现在定义变量一般使用const 或者let 很少使用var</div>
</template>

<script setup lang="ts" name="Hoisting">
const a = 10;
const fn = () => {};
const text = () => {
  let a;
  a = 100;
  console.log(a);
  console.log(fn);
};
text();
console.log(a);

const arr = [{ name: "b1" }, { name: "b2" }, { name: "b3" }];

const bind = () => {
  for (let i = 0; i < arr.length; i++) {
    (arr[i] as any).fun = () => {
      alert(i);
    };
  }
};
bind();
// (arr[0] as any).fun();
// (arr[1] as any).fun();
// (arr[2] as any).fun();

const aaa = () => {
  const a = 1;
  const bbb = () => {
    console.log(a);
  };
  bbb();
};

aaa();



</script>

<style scoped lang="scss"></style>
